//
//  CartImformationCell.m
//  DingDongXiChe
//
//  Created by wtjr on 2017/11/28.
//  Copyright © 2017年 xieyingze. All rights reserved.
//

#import "CarImformationCell.h"

@interface CarImformationCell()

@property (nonatomic, strong) UIView *mainView;

@property (nonatomic, strong) CustomReuseCellView *carTypeView;



@end

@implementation CarImformationCell

#pragma mark - ********************生命周期********************

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    static NSString *cellId = @"CarImformationCell";
    CarImformationCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[CarImformationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

#pragma mark - 内部方法

- (void)initSubView {
    self.backgroundColor = kCOLOR_tableView;
    [self addSubview:self.mainView];
    [self.mainView addSubview:self.carTypeView];
    [self.mainView addSubview:self.carNumberView];
}

- (void)autoLayoutSubviews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0).insets(UIEdgeInsetsMake(5, 5, 5, 5));
    }];
    [self.carTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(@0);
        make.height.equalTo(@(kUI_CellHeight));
    }];
    [self.carNumberView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.carTypeView.mas_bottom);
        make.height.equalTo(self.carTypeView);
    }];
}

- (void)bindViewModel {
    @weakify(self);
    [[self.carTypeView.selectButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if (self.selectCarTypeCompleted) {
            self.selectCarTypeCompleted();
        }
    }];
}

#pragma mark - 点击事件

#pragma mark - 外部方法

#pragma mark - Setter

- (void)setViewModel:(OrderViewModel *)viewModel {
    _viewModel = viewModel;
    @weakify(self);
    [RACObserve(viewModel, carBrand) subscribeNext:^(NSString *x) {
        @strongify(self);
        self.carTypeView.clickTitle = x.length > 0 ? x : @"选择车辆";
    }];
}

#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        [_mainView setViewShadow:kCOLOR_shadow offset:CGSizeMake(0, 0) radius:1];
    }
    return _mainView;
}

- (CustomReuseCellView *)carTypeView {
    if (!_carTypeView) {
        _carTypeView = [CustomReuseCellView new];
        _carTypeView.iconName = @"dd_package_package";
        _carTypeView.title = @"车辆型号";
        _carTypeView.cellType = kCustomCellTypeClick;
        _carTypeView.clickTitle = @"点击选择型号";
        _carTypeView.showLine = YES;
    }
    return _carTypeView;
}

- (CustomReuseCellView *)carNumberView {
    if (!_carNumberView) {
        _carNumberView = [CustomReuseCellView new];
        _carNumberView.iconName = @"dd_package_duration";
        _carNumberView.title = @"车牌号码";
        _carNumberView.cellType = kCustomCellTypeInput;
        _carNumberView.showLine = NO;
    }
    return _carNumberView;
}

@end
